#version 450 compatibility




layout(local_size_x = DEF_LocalSize, local_size_y = 1, local_size_z = 1) in;


layout( binding = 0, rgba8ui) uniform uimage2D Pix;

layout( binding = 1 ) uniform Buf_LoalParameter1 {
    ivec2   m_Offset;
    vec2    m_WidgetOffset;
    uint    m_Color;
    uint    m_Dir;
    vec2    m_HVgap;
};



void main(){
    ivec2 coord = ivec2(gl_WorkGroupID.x, gl_WorkGroupID.y);
    if(m_Dir == 0){
        coord.y = int(float(coord.y) * m_HVgap.y);

        coord += m_Offset;
        coord.y += int(m_WidgetOffset.y - (int(m_WidgetOffset.y/m_HVgap.y) * m_HVgap.y));
        //if(m_WidgetOffset.y < 0){ } 在应用程序中判断偏移是否为负
        
    } else {
        coord.x = int(float(coord.x) * m_HVgap.x);

        coord += m_Offset;
        coord.x += int(m_WidgetOffset.x - (int(m_WidgetOffset.x/m_HVgap.x)*m_HVgap.x));
        //if(m_WidgetOffset.x < 0){ } 在应用程序中判断偏移是否为负
        
    }

    
    uvec4 c = uvec4(bitfieldExtract(m_Color, 0, 8), 
                    bitfieldExtract(m_Color, 8, 8), 
                    bitfieldExtract(m_Color, 16, 8), 
                    bitfieldExtract(m_Color, 24, 8));
    
    float alp = (float(c.a) / 255.0);
    uvec4 color = imageLoad(Pix, coord);
    c.r = uint(float(color.r)*(1-alp) + float(c.r)*alp);
    c.g = uint(float(color.g)*(1-alp) + float(c.g)*alp);
    c.b = uint(float(color.b)*(1-alp) + float(c.b)*alp);
    c.a = 255;

    imageStore(Pix, coord, c);
}





